define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'driving/freight_rule/index' + location.search,
                    add_url: 'driving/freight_rule/add',
                    edit_url: 'driving/freight_rule/edit',
                    del_url: 'driving/freight_rule/del',
                    multi_url: 'driving/freight_rule/multi',
                    import_url: 'driving/freight_rule/import',
                    table: 'driving_freight_rule',
                }
            });

            var table = $("#table");
            var extend = $.fn.bootstrapTable.defaults.extend;

            $('.btn-add').data('area', ['90%', '100%']);
            table.on('post-body.bs.table', function(e, setting, json, xhr) {
                $('.btn-editone,.btn-edit').data('area', ['90%', '100%']);
            });

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false, sortable: true},
                        {field: 'freight_id', title: __('Freight_id')},
                        {field: 'in_time_start', title: __('In_time_start'), operate: 'LIKE'},
                        {field: 'in_time_end', title: __('In_time_end'), operate: 'LIKE'},
                        {field: 'in_start_price', title: __('In_start_price'), operate:'BETWEEN'},
                        {field: 'in_start_kl', title: __('In_start_kl')},
                        {field: 'in_protect_kl', title: __('In_protect_kl')},
                        {field: 'in_time_top', title: __('In_time_top')},
                        {field: 'in_price_top', title: __('In_price_top'), operate:'BETWEEN'},
                        {field: 'et_start_price', title: __('Et_start_price'), operate:'BETWEEN'},
                        {field: 'et_start_kl', title: __('Et_start_kl')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
